package com.gzx.spring.db.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.gzx.spring.db.entity.CreditUserAuthorization;
import com.gzx.spring.db.mapper.CreditUserAuthorizationMapper;
import com.gzx.spring.db.service.CreditUserAuthorizationService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

/**
 * <p>
 * 征信用户授权表 服务实现类
 * </p>
 *
 * @author qinpeng
 * @since 2025-11-10
 */
@Service
public class CreditUserAuthorizationServiceImpl extends ServiceImpl<CreditUserAuthorizationMapper, CreditUserAuthorization> implements CreditUserAuthorizationService {

    @Override
    public CreditUserAuthorization getLatestValidByUid(Long uid) {
        LambdaQueryWrapper<CreditUserAuthorization> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(CreditUserAuthorization::getUid,uid);
        wrapper.ne(CreditUserAuthorization::getSerialNumber,"");
        wrapper.gt(CreditUserAuthorization::getAuthExpireDatetime, LocalDateTime.now());
        wrapper.orderByDesc(CreditUserAuthorization::getAuthExpireDatetime);
        return this.getOne(wrapper,false);
    }
}
